// types/api.ts - 基于 swagger.yaml 的类型定义

// ========== 连接管理 ==========
export interface ConnectionDetail {
  connected: boolean;
  hostname: string;
  name: string;
  uri: string;
  version: number;
}

export interface CreateConnectionRequest {
  name: string;
  uri: string;
  set_as_default?: boolean;
}

// ========== 虚拟机管理 ==========
export interface DomainDetail {
  cpu_time?: number; // CPU time in nanoseconds
  max_memory: number; // Max memory in KiB
  memory: number; // Current memory in KiB
  name: string;
  state: string;
  uuid: string;
  vcpus: number;
  xml_config?: string;
}

export interface CreateDomainRequest {
  name: string;
  disk_path: string;
  uuid?: string;
  memory?: number; // Memory in MiB
  vcpus?: number;
  disk_size?: number; // Disk size in GiB
  disk_bus?: 'virtio' | 'sata' | 'scsi';
  network_mode?: 'network' | 'bridge' | 'user';
  network_name?: string;
  architecture?: 'x86_64' | 'aarch64';
  boot_mode?: 'bios' | 'uefi';
  secure_boot?: boolean;
  os_variant?: string; // OS variant for libosinfo
  auto_start?: boolean;
  cdrom_boot?: boolean;
  cdrom_path?: string;
  cdrom_bus?: 'ide' | 'sata' | 'scsi';
}

export interface DomainSummary {
  name: string;
  uuid: string;
  state: string;
  memory: number;
  vcpus: number;
}

export interface DomainStats {
  cpu_time?: number;
  cpu_stats?: Record<string, number>;
  memory_stats?: Record<string, number>;
  block_stats?: Record<string, any>;
  net_stats?: Record<string, any>;
}

// ========== 存储管理 ==========
export interface StoragePoolDetail {
  active: boolean;
  allocation: number;
  available: number;
  capacity: number;
  name: string;
  type: string;
  uuid: string;
  xml_config?: string;
}

export interface StoragePoolSummary {
  name: string;
  uuid: string;
  active: boolean;
  capacity: number;
  available: number;
}

export interface StorageVolumeDetail {
  allocation: number;
  capacity: number;
  name: string;
  path: string;
  type: string;
  xml_config?: string;
}

export interface CreateVolumeRequest {
  name: string;
  capacity: number; // Capacity in bytes
  format?: 'qcow2' | 'raw'; // qcow2, raw, etc.
}

export interface StorageVolumeSummary {
  name: string;
  path: string;
  capacity: number;
  allocation: number;
}

// ========== 网络管理 ==========
export interface NetworkDetail {
  active: boolean;
  bridge: string;
  name: string;
  uuid: string;
  xml_config?: string;
}

export interface NetworkSummary {
  name: string;
  uuid: string;
  active: boolean;
  bridge: string;
}

// ========== 系统信息 ==========
export interface SystemInfo {
  hostname: string;
  hypervisor_version: number;
  libvirt_version: number;
  uri: string;
}

// ========== 控制台管理 ==========
export interface ConsoleInfo {
  type: 'vnc' | 'spice' | 'serial';
  host?: string;
  port?: number;
  password?: string;
  path?: string;
}

// ========== API 响应类型 ==========
export interface ApiResponse<T = any> {
  message?: string;
  data?: T;
  [key: string]: any;
}

export interface ListResponse<T> {
  count: number;
  items?: T[];
  // 根据实际 API 响应调整字段名
  connections?: T[];
  domains?: T[];
  pools?: T[];
  volumes?: T[];
  networks?: T[];
}

// ========== 错误响应 ==========
export interface ApiError {
  error: string;
  message: string;
  status?: number;
}

// ========== 操作参数 ==========
export interface SetMemoryRequest {
  memory: number; // in KiB
}

export interface SetVCPUsRequest {
  vcpus: number;
}

// ========== 枚举类型 ==========
export enum DomainState {
  RUNNING = 'running',
  SHUT_OFF = 'shut off',
  PAUSED = 'paused',
  SUSPENDED = 'suspended',
  CRASHED = 'crashed',
}

export enum BootMode {
  BIOS = 'bios',
  UEFI = 'uefi',
}

export enum DiskBus {
  VIRTIO = 'virtio',
  SATA = 'sata',
  SCSI = 'scsi',
  IDE = 'ide',
}

export enum NetworkMode {
  NETWORK = 'network',
  BRIDGE = 'bridge',
  USER = 'user',
}

export enum Architecture {
  X86_64 = 'x86_64',
  AARCH64 = 'aarch64',
}